package com.lexin.common.utils;

import java.sql.Timestamp;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

public class DateUtil {
	
	/***
	 * 格式化日期
	 * @param time
	 * @param Pattern
	 * @return
	 */
	public static String format (Timestamp time, String pattern) {
		if (time==null) {
			return now(pattern);
		}
		DateFormat sdf = new SimpleDateFormat(pattern);
		return sdf.format(time);
	}
	
	/***
	 * 获取现在字符串形式的日期
	 * @param pattern
	 * @return
	 */
	public static String now(String pattern) {
		DateFormat sdf = new SimpleDateFormat(pattern);
		Timestamp time = new Timestamp(new Date().getTime());
		return sdf.format(time);
	}
	
	/***
	 * 获取现在的时间
	 * @return
	 */
	public static Timestamp now() {
		return new Timestamp(new Date().getTime());
	}
}
